package org.zju.demo.mina;

import org.springframework.beans.factory.annotation.Autowired;
import org.zju.demo.model.UAVStatus;
import org.zju.demo.service.impl.UavStatusService;
import org.zju.demo.service.intf.UavStatusInft;

import java.util.Date;

/**
 * Created by ZJDX on 2015/9/17.
 */
public class UavHandler extends AbstractHandler {

    private static final int COMMAND_BATTERY = 0x01;

    private final  UavStatusInft uavStatusService = new UavStatusService();
    public UavHandler(byte[] buffer) {
        super(buffer);
    }

    @Override
    public String handle() {
        int uavId = getId();
        int data = getData(); // 表明电量百分比
        switch (getCommandType()) {
            case COMMAND_BATTERY:
                UAVStatus uavStatus = new UAVStatus();
                uavStatus.setBattery(data);
                uavStatus.setTime(new Date());
                uavStatus.setUavId(uavId);
                uavStatusService.add(uavStatus);
                break;
            default:
        }

        return null;
    }
}
